from django import forms
from core.models.student import Student
from core.models.classinfo import ClassInfo

class StudentForm(forms.ModelForm):
    class Meta:
        model = Student
        fields = ['name', 'birthday', 'gender', 'enrollment_date', 'contact_info', 'home_address', 'family_background']
        widgets = {
            'birthday': forms.DateInput(attrs={'type': 'date'}),
            'enrollment_date': forms.DateInput(attrs={'type': 'date'}),
        }

    def __init__(self, *args, **kwargs):
        self.user = kwargs.pop('user', None)
        super().__init__(*args, **kwargs)
        # 如果提供了用户，过滤班级选项为用户管理的班级